<template>
  <!-- 打分记录页面 -->
  <div class="app-container">
    <el-row :gutter="20">
      <!--教师基本信息-->
      <!-- <el-col :span="4" :xs="5">
        <treeIndex :deptOptions="deptOptions" @handleNode="handleNodeClick" :title="'部门信息'"></treeIndex>
      </el-col> -->
      <el-col :span="24" :xs="24">
        <searchForm
          :formOptions="formOptions"
          @onSearch="onSearch"
          @onReset="onReset"
          :formLabelWidth="formLabelWidth"
          v-show="showSearch"
        />
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['clr:examinescoring:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="examinescoringList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index"/>
      <!-- <el-table-column label="xue" align="center" prop="amcYear" /> -->
      <el-table-column label="学年" align="center" prop="amcYear" />
      <el-table-column label="批次名称" align="center" prop="batchName" />
      <el-table-column label="辅导员工号" align="center" prop="clrTno" />
      <el-table-column label="辅导员姓名" align="center" prop="clrName"/>
      <el-table-column label="所在院系" align="center" prop="deptName"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)"
            v-hasPermi="['clr:examinescoring:query']">查看考核人员</el-button>
        </template>
      </el-table-column>
    </el-table>


    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    </el-col>
    </el-row>
    <!-- 添加或修改辅导员考核打分记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-table v-loading="loading" :data="clrExamineScoringMonads.clrExamineScoringMonads" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="打分人工号" align="center" prop="eNo" />
      <el-table-column label="打分人姓名" align="center" prop="eName" />
      <el-table-column label="指标总分数" align="center" prop="sumScore" />
      <!-- <el-table-column label="批次年级" align="center" prop="gradeField">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.clr_grade_type" :value="scope.row.gradeField" />
        </template>
      </el-table-column>
      <el-table-column label="考核体系" align="center" prop="ceeName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.clr_exam_systype" :value="scope.row.ceeName" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="指标分类" align="center" prop="cecName" />
      <el-table-column label="指标名称" align="center" prop="fieldName" />
      <el-table-column label="考核人工号" align="center" prop="eNo" />
      <el-table-column label="考核人名称" align="center" prop="eName" />
      <el-table-column label="分数" align="center" prop="score" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="viewScore(scope.row)"
            v-hasPermi="['clr:examinescoring:query']">分数详情</el-button>
        </template>
      </el-table-column>
    </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listExaminescoring, getExaminescoring, delExaminescoring, addExaminescoring, updateExaminescoring } from "@/api/clr/examinescoring";
import searchForm from "@/components/Search/searchForm.vue";
import { deptTreeSelect } from "@/api/system/user";
import treeIndex from "@/components/tree/index.vue";
import { getSelector} from "@/api/clr/batch";
import {
  collegeSelect
} from "@/api/information/studentInfor"
export default {
  name: "Examinescoring",
  dicts:[
    'clr_grade_type', // 年级批次
    'clr_exam_systype', // 考核体系
  ],
  components: {
    treeIndex,
    searchForm
  },
  data() {
    return {
      formLabelWidth: "85px",
      formOptions: [
        {
          label: "院系",
          prop: "deptId",
          element: "el-select",
          options: [],
          placeholder: "请选择院系"
        },
        {
          label: "辅导员工号",
          prop: "clrTno",
          element: "el-input",
          placeholder: "请输入辅导员工号",
        },
        {
          label: "辅导员姓名",
          prop: "clrName",
          element: "el-input",
          placeholder: "请输入辅导员姓名"
        },
        {
          label: "批次名称",
          prop: "cebId",
          element: "el-select",
          options: [],
          placeholder: "请输入批次名称"
        },
        {
          label: "学年",
          prop: "amcYears",
          type: "monthrange",
          element: "el-date-picker",
          placeholder: "请选择学年",
          valueFormat: "yyyy-MM"
        }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      gardeType:'',
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 辅导员考核打分记录表格数据
      examinescoringList: [],
      clrExamineScoringMonads: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      deptOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cemId: null,
        ceeId: null,
        cebfId: null,
        eId: null,
        eNo: null,
        eName: null,
        score: null
      },
      // 表单参数
      form: {},
      names:[],
      // 表单校验
      rules: {
      }
    };
  },
  async created() {
    this.department()
    await getSelector({cebType:'A'}).then(res => {
      this.formOptions[3].options = res.data.map(item => {
        return {
          value: item["CEBID"],
          label: item["BATCHNAME"]
        };
      });
    })
    this.getList();
  },
  methods: {
     // 获取搜索表单提交的数据
     onSearch(val) {
      // 查询条件和分页数据合并
      if(val.amcYears) {
        val.startAmcYear = val.amcYears[0];
        val.endAmcYear = val.amcYears[1];
      }
      this.queryParams = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      data.startAmcYear = undefined
      data.endAmcYear = undefined
      this.queryParams.pageNum = 1;
      this.queryParams.deptId = '';
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    /** 查询辅导员考核打分记录列表 */
    getList() {
      this.loading = true;
      listExaminescoring(this.queryParams).then(response => {
        this.examinescoringList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     // tree树形选中的值
     handleNodeClick(data) {
      console.log(data, "选中的值");
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 获取部门信息
    async department() {
      await collegeSelect().then(res => {
        // this.deptOptions = res.data;
        this.formOptions[0].options = res.data.map(item => {
          return {
            value: item.deptId,
            label: item.deptName
          };
        });
      });
    },
    
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cemId)
      this.names = selection.map(item => item.clrName)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加辅导员考核打分记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
     
      const cesId = row.cesId || this.ids
      getExaminescoring(cesId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改辅导员考核打分记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cesId != null) {
            updateExaminescoring(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addExaminescoring(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 分数详情
    viewScore(row) {
      this.$router.push({ name: "Score", params: this.clrExamineScoringMonads });
    },
    /** 查看详情 */
    handleView(row) {
      this.title = '查看考核人员'
      getExaminescoring(row.cemId).then(res => {
      console.log(res,'打分记录')
      this.open = true
      this.clrExamineScoringMonads = res.data
      // this.clrExamineScoringMonads = res.data.clrExamineScoringMonads


    })
      // this.$router.push({ name: "Score", params: row });
      // const cesIds = row.cesId || this.ids;
      // this.$modal.confirm('是否确认删除辅导员考核打分记录编号为"' + cesIds + '"的数据项？').then(function () {
      //   return delExaminescoring(cesIds);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => { });
    },
      /** 删除按钮操作 */
      /** 删除按钮操作 */
    handleDelete(row) {
      console.log(row)
      const cexIds = row.cemId || this.ids;
      this.names = row.clrName || this.names;
      this.$modal
        .confirm('是否确认删除辅导员"' + this.names + '"的打分记录？')
        .then(function() {
          return delExaminescoring(cexIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('clr/examinescoring/export', {
        ...this.queryParams
      }, `examinescoring_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
